<#assign form=JspTaglibs["http://www.springframework.org/tags/form"] />
<#include "./template.ftl">
<#macro head>
<title>发布文章</title>
<link rel="stylesheet" href="${base}/client/css/fabu.css">
<link href='${base}/system/charisma-static/css/uploadify.css' rel='stylesheet'>
</#macro>
<#macro content>
    <div id="contents" class="fabu-contents" style="background-color: #FFFFFF;">
          <div class="main wrap clearfix">
            <@form.form modelAttribute="editPostsCommand" role="form">
               <div class="fabu-wrap" style="width: 70%;">
                    <h1>发布文章</h1>
                   <@form.errors path='*' element="div" cssStyle="color:red"/>
                    <h2 class="title">文章预览图<span>*(图片尺寸850*500，格式png、jpg、gif等，大小2M以内)</span></h2>
                   <div id="imgBlock">
                       <@form.hidden path="postImg" id="iconUrlImg"/>
                       <#if editPostsCommand.postImg?? && editPostsCommand.postImg != "">
                           <img style='width:200px;' src='${base}/system/getImg?imgId=${editPostsCommand.postImg}&w=200'/>
                       </#if>
                   </div>
                    <div>
                        <input data-no-uniform="true" type="file" id="imgSel" class="file_upload">
                    </div>
                    <h2 class="title">文章标题<span>*</span></h2>
                    <div class="fabu-title">
                        <@form.input path="postTitle" id="title"/>
                    </div>
                    <h2 class="title">文章内容<span>*</span></h2>
                    <div class="fabu-article">
                        <@form.textarea cssStyle="height:400px;" path="postContent" id="post_content"></@form.textarea>
                    </div>

                    <div class="btn">
                        <button type="submit">提交</button>
                    </div>
               </div>
            </@form.form>
          </div>
    </div>
</#macro>
<#macro js>
    <script src="${base}/system/charisma-static/bower_components/jquery/jquery.min.js"></script>
    <script src="${base}/system/charisma-static/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${base}/system/ueditor_1_4_3_1/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="${base}/system/ueditor_1_4_3_1/ueditor.all.min.js"></script>
    <script src="${base}/system/charisma-static/js/jquery.uploadify-3.1.min.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function () {

        UE.getEditor('post_content');

        $('#imgSel').uploadify({
            'swf': '${base}/system/charisma-static/misc/uploadify.swf',
            'uploader': '${base}/system/uploadImg',
            'fileTypeExts': '*.jpg;*.gif;*.jpeg;*.png;',
            'buttonText': '请选择图片',
            'fileObjName': 'file',
            'multi': false,
            onSelect: function (file) {//当每个文件添加至队列后触发
                if (file.size >= 2 * 1024 * 1024) {
                    alert("选择文件不能超过10MB");
                    return false;
                }
            },
            onError: function (event, queueID, fileObj) {
                alert("文件:" + fileObj.name + "上传失败");
            },
            onUploadSuccess: function (file, data, response) {
                data = JSON.parse(data);
                $("#imgBlock img").remove();
                $("#imgBlock").append("<img style='width:200px;' src='${base}/system/getImg?imgId=" + data.filePath + "&w=200'/>");
                $("#iconUrlImg").val(data.filePath);
            }
        });
    });

</script>
</#macro>
